class LabelEditorPureCanvas_Other {
    public LoadImageByUrl(url: string): Promise<HTMLImageElement> {
        return new Promise<HTMLImageElement>(async (resolve, reject) => {
            let returnImage: HTMLImageElement = new Image();
            returnImage.src = url;
            returnImage = await this.waitForImageLoaded(returnImage);
            resolve(returnImage);
        });
    }

    public waitForImageLoaded(imageElement: HTMLImageElement) {
        return new Promise<HTMLImageElement>((resolve, reject) => {
            imageElement.onload = () => {
                resolve(imageElement);
            }
            imageElement.onerror = () => {
                reject(new Error("图像加载失败"));
            }
        });
    }
    public GetTextColor(txtAttr: any, invertColorArea: any, canKao: any): string {
        if (invertColorArea == undefined) {
            let color: string = "#000000";
            if (txtAttr.color != undefined) {
                color = txtAttr.color;
            }
            if (txtAttr.opacity == undefined) {
                return color;
            } else {
                var charList = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
                var theCharIndex = Math.round(txtAttr.opacity / (1 / charList.length));
                var theChar = charList[theCharIndex];
                return color + theChar + theChar
            }
        } else {
            // if (canKao.value.indexOf("收纳柜0点91") != -1) {
            //     debugger;
            // }
            let L1: number = txtAttr.left;
            let R1: number = txtAttr.left + txtAttr.width;
            let T1: number = txtAttr.top;
            let B1: number = txtAttr.top + txtAttr.height;

            let L2: number = invertColorArea[0];
            let R2: number = invertColorArea[0] + invertColorArea[2];
            let T2: number = invertColorArea[1];
            let B2: number = invertColorArea[1] + invertColorArea[3];

            if (this.HasInverset(L1, R1, L2, R2) && this.HasInverset(T1, B1, T2, B2)) {
                return "#ffffff";
            } else {
                return "#000000";
            }
        }
    }

    public HasInverset(min1: number, max1: number, min2: number, max2: number): boolean {
        if (min2 < max1 && max1 < max2) {
            return true;
        } else if (min2 < min1 && min1 < max2) {
            return true;
        }
        else if (min1 < min2 && min2 < max1) {
            return true;
        } else if (min1 < max2 && max2 < max1) {
            return true;
        }
        return false
    }
}